# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from tortoise import fields
from kernels.model import DbModel


class DocsFilesModel(DbModel):
    id = fields.IntField(pk=True, description="主键")
    user_id = fields.IntField(null=False, default=0, description="用户ID")
    code = fields.CharField(null=False, max_length=32, default="", description="文件编号")
    mode = fields.CharField(null=False, max_length=10, default="", description="文件模式")
    name = fields.CharField(null=False, max_length=200, default="", description="文件名称")
    size = fields.IntField(null=False, default=0, description="文件大小")
    ext = fields.CharField(null=False, max_length=10, default="", description="文件扩展")
    raw_path = fields.CharField(null=False, max_length=250, default="", description="原始文件")
    pdf_path = fields.CharField(null=False, max_length=250, default="", description="PDF文件")
    txt_path = fields.CharField(null=False, max_length=250, default="", description="TXT文件")
    vector_models = fields.CharField(null=False, max_length=200, default="", description="向量模型")
    vector_alias = fields.CharField(null=False, max_length=100, default="", description="向量别名")
    ip = fields.CharField(null=False, max_length=64, default="", description="来源IP")
    error = fields.TextField(null=False, default="", description="失败原因")
    status = fields.IntField(null=False, default=0, description="训练状态: [0=待训练,1=训练中,2=训练成功,3=训练失败]")
    is_delete = fields.SmallIntField(null=False, default=0, description="是否删除: [0=否, 1=是]")
    create_time = fields.IntField(null=False, default=0, description="创建时间")
    update_time = fields.IntField(null=False, default=0, description="更新时间")
    delete_time = fields.IntField(null=False, default=0, description="删除时间")

    class State:
        WAIT = 0     # 等待中
        RUNNING = 1  # 解析中
        SUCCESS = 2  # 解析成功
        FAILED = 3   # 解析失败

    class Meta:
        table_description = "畅阅文件表"
        table = DbModel.table_prefix("docs_files")


class DocsPromptModel(DbModel):
    id = fields.IntField(pk=True, description="主键")
    code = fields.CharField(null=False, max_length=10, default="", description="编号")
    icon = fields.CharField(null=False, max_length=250, default="", description="图标")
    name = fields.CharField(null=False, max_length=100, default="", description="名称")
    intro = fields.CharField(null=False, max_length=200, default="", description="简介")
    abstract_conf = fields.TextField(null=False, default="", description="摘要提示词")
    dialogue_conf = fields.TextField(null=False, default="", description="对话提示词")
    sort = fields.IntField(null=False, default=0, description="排序编号")
    is_builtin = fields.SmallIntField(null=False, default=0, description="系统内置: [0=否, 1=是]")
    is_disable = fields.SmallIntField(null=False, default=0, description="是否禁用: [0=否, 1=是]")
    is_delete = fields.SmallIntField(null=False, default=0, description="是否删除: [0=否, 1=是]")
    create_time = fields.IntField(null=False, default=0, description="创建时间")
    update_time = fields.IntField(null=False, default=0, description="更新时间")
    delete_time = fields.IntField(null=False, default=0, description="删除时间")

    class Meta:
        table_description = "畅阅模式表"
        table = DbModel.table_prefix("docs_prompt")


class DocsRecordsModel(DbModel):
    id = fields.IntField(pk=True, description="主键")
    user_id = fields.IntField(null=False, default=0, description="用户ID")
    file_id = fields.IntField(null=False, default=0, description="文件ID")
    code = fields.CharField(null=False, max_length=32, default="", description="编号")
    scene = fields.CharField(null=False, max_length=10, default="", description="场景: [chat=对话]")
    question = fields.TextField(default="", description="提问问题")
    thinks = fields.TextField(default="", description="思考过程")
    answer = fields.TextField(default="", description="答复内容")
    use_points = fields.IntField(null=False, default=0, description="消耗积分")
    use_tokens = fields.IntField(null=False, default=0, description="消耗Tokens")
    quotes = fields.TextField(null=False, default="", description="引用内容")
    flows_usage = fields.TextField(description="消耗流程")
    end_clear = fields.SmallIntField(null=False, default=0, description="清除末端: [0=否, 1=是]")
    is_clear = fields.SmallIntField(null=False, default=0, description="是否清除: [0=否, 1=是]")
    is_delete = fields.SmallIntField(null=False, default=0, description="是否删除: [0=否, 1=是]")
    ip = fields.CharField(null=False, max_length=64, default="", description="来源IP")
    task_time = fields.CharField(null=False, max_length=20, default="", description="执行耗时")
    create_time = fields.IntField(null=False, default=0, description="创建时间")
    update_time = fields.IntField(null=False, default=0, description="更新时间")
    delete_time = fields.IntField(null=False, default=0, description="删除时间")

    class Meta:
        table_description = "畅阅记录表"
        table = DbModel.table_prefix("docs_records")
